<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        
        <input type="text" v-model="n1" >
        <select v-model="opt">
            <option>+</option>
            <option>-</option>
            <option>*</option>
            <option>/</option>
        </select>
        <input type="text" v-model="n2" >
        <input type="button" value="计算"  @click="clac">
        <input type="text" v-model="result">
    </div>

    <script src="lib/vue-2.4.0.js"></script>
    <script>
        var vm = new Vue({
            el:'#app',
            data:{
                opt:'+',
                n1:'1',
                n2:'2',
                result:'3'
            },
            methods:{
                clac(){
                    switch(this.opt){
                        case '+':
                            this.result = parseInt(this.n1)+parseInt(this.n2);
                            break;
                        case '-':
                            this.result = parseInt(this.n1)-parseInt(this.n2);
                            break;
                        case '*' :
                            this.result = parseInt(this.n1)*parseInt(this.n2);
                            break;
                        case '/':
                            this.result = parseInt(this.n1)/parseInt(this.n2);
                            break;        

                    }
                     // 注意：这是投机取巧的方式，正式开发中，尽量少用
                    // var codeStr = 'parseInt(this.n1) ' + this.opt + ' parseInt(this.n2)'
                    // this.result = eval(codeStr)
                }
            }
        })
    </script>
</body>
</html>